//
//  tintyCell.m
//  TinyFortune
//
//  Created by lc on 16/5/22.
//  Copyright © 2016年 lc. All rights reserved.
//

#import "tintyCell.h"
#import "tinyFrameModel.h"
#import "tinyDataModel.h"
//头像
//名字
//时间
//图片
//内容
//点赞
//评论
//举报
@implementation tintyCell{
    UIImageView *_iconImageView;//头像
    UILabel *_nameLabel ;//名字
    UILabel *_timeLabel;//时间
    UIImageView *_photoImageView;//图片
    UILabel *_textLabel ;//文字
    UIButton *_favouriteButton;//赞
    UIButton *_commendButton;//评论
   

}

#pragma mark - 实例化子视图,并且添加到cell上
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [ super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
       
        //名字
        _nameLabel = [UILabel new];
       // _nameLabel.textColor = [UIColor redColor];
        _nameLabel.textColor = [UIColor colorWithRed:1/255.0f green:1/255.0f blue:1/255.0f alpha:0.6];
        [self.contentView addSubview:_nameLabel];
        _nameLabel.font = [UIFont systemFontOfSize:17];
        //时间
        _timeLabel = [UILabel new];
        [self.contentView addSubview:_timeLabel];
         _timeLabel.font = [UIFont systemFontOfSize:11];
        //图片
        _photoImageView = [UIImageView new];
        [self.contentView addSubview:_photoImageView];
        _photoImageView.layer.cornerRadius = 7 ;
        _photoImageView.layer.masksToBounds = YES ;
        //头像
        _iconImageView = [UIImageView new];
        _iconImageView.layer.masksToBounds = YES ;
        [self.contentView addSubview:_iconImageView];
        //内容
        _textLabel = [[UILabel alloc]init];
        _textLabel.numberOfLines = 0;
        [self.contentView addSubview:_textLabel];
         _textLabel.font = [UIFont systemFontOfSize:15];
        //点赞
        _favouriteButton = [UIButton new];
        [self.contentView addSubview:_favouriteButton];
        //评论
        _commendButton = [UIButton new];
        [self.contentView addSubview:_commendButton];
      
        
    }
    return self;
}
#pragma mark -计算frame
- (void)layoutSubviews{
    [super layoutSubviews];
    //头像
    _iconImageView.frame = _frameModel.iconFrame;
    _iconImageView.layer.cornerRadius = _iconImageView.frame.size.height/2.0f;
    //名字
    _nameLabel.frame = _frameModel.nameFrame;
    //时间
    _timeLabel.frame = _frameModel.timeFrame;
    //图片
    _photoImageView.frame = _frameModel.photoFrame;
    //内容
    _textLabel.frame = _frameModel.textFrame;
    //点赞
    _favouriteButton.frame = _frameModel.favouriteFrame;
    //评论
    _commendButton.frame = _frameModel.commendFrame;
 
    
    
}
#pragma mark -给子视图赋值
- (void)setDataModel:(tinyDataModel *)dataModel{
    _dataModel = dataModel;
    //头像
    [_iconImageView sd_setImageWithURL:[NSURL URLWithString:_dataModel.icon] placeholderImage:nil];
    [_iconImageView setContentMode:UIViewContentModeScaleAspectFill];
    _iconImageView.clipsToBounds = YES ;
    //名字
    _nameLabel.text = _dataModel.name;
    
    //时间
    _timeLabel.text = _dataModel.time;

    //图片
    [_photoImageView sd_setImageWithURL:[NSURL URLWithString:_dataModel.photo] placeholderImage:[UIImage imageNamed:@"default_avatar"]];
    [_photoImageView setContentMode:UIViewContentModeScaleAspectFill];
    _photoImageView.clipsToBounds = YES ;
    //内容
    _textLabel.text = _dataModel.text;
  
    
    //赞按钮设置
    [_favouriteButton setImage:[UIImage imageNamed:@"like_outline_16px_1172555_easyicon.net"] forState:UIControlStateNormal];
    [_favouriteButton setTitle:@"赞" forState:UIControlStateNormal];
    [_favouriteButton setImage:[UIImage imageNamed:@"Heart_love_16px_1096413_easyicon.net"] forState:UIControlStateSelected];
    [_favouriteButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    _favouriteButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [_favouriteButton addTarget:self action:@selector(favourite:) forControlEvents:UIControlEventTouchDown];
    //评论按钮设置
    [_commendButton setImage:[UIImage imageNamed:@"comments_16px_585571_easyicon.net-2"] forState:UIControlStateNormal];
    [_commendButton setTitle:@"评论" forState:UIControlStateNormal];
    [_commendButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    _commendButton.titleLabel.font = [UIFont systemFontOfSize:13];
   //评论内容
    
}
#pragma mark - 点击事件
- (void)favourite:(UIButton *)sender{
    sender.selected = !sender.selected ;
}

@end
